// 组件
import headerComponent from '@src/components/header'
import sidebarComponent from '@src/components/sidebar'
import footerComponent from '@src/components/footer'
import contentComponent from '@src/components/content'

// 视图
import view from '@src/views/index'

// 路由配置
import routes from '@src/routes';

// service
import { handleLogout } from '@src/service/login.js'


export default (req, res, next) => {
  next(
    view({
      content: contentComponent({
        content: res.subRoute(),
        title: routes.find(item => item.path === req.url)?.title
      }),
      header: headerComponent(),
      sidebar: sidebarComponent({
        activeUrl: req.url,
        routes: routes
      }),
      footer: footerComponent(),
    })
  );

  document.querySelector("#logoutBtn").addEventListener('click', handleLogout)
}